package com.ss.project.xia17user.config.security.form;

import com.ss.project.xia17user.dao.entity.User;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

import java.util.Collection;
import java.util.Collections;

/**
 *  Form 登录授权信息
 * @author xia17
 * @date 2020/6/21
 */
@RequiredArgsConstructor
public class FormAuthentication implements Authentication {

    private final String username ;
    private final Object credentials;
    private final LoginMethod loginMethod;
    private boolean authenticated;
    private User user;

    public void setUser(User user) {
        this.user = user;
    }

    public User getUser(){
        return this.user;
    }

    public LoginMethod loginMethod(){
        return this.loginMethod;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Collections.singletonList(new SimpleGrantedAuthority("admin"));
    }

    @Override
    public Object getCredentials() {
        return this.credentials;
    }

    @Override
    public Object getDetails() {
        return this.user;
    }

    @Override
    public Object getPrincipal() {
        return this.user;
    }

    @Override
    public boolean isAuthenticated() {
        return this.authenticated;
    }

    @Override
    public void setAuthenticated(boolean authenticated){
        this.authenticated = authenticated;
    }

    @Override
    public String getName() {
        return this.username;
    }
}
